package com.hgyc.mom.mes.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hgyc.mom.common.util.poi.ExcelUtil;
import com.hgyc.mom.common.vo.Result;
import com.hgyc.mom.core.mybatis.QueryWrapperUtil;
import com.hgyc.mom.mes.entity.MesStationCollect;
import com.hgyc.mom.mes.service.MesStationCollectService;
import com.hgyc.mom.mes.vo.CollectScanVO;
import com.hgyc.mom.mes.vo.MesStationCollectParam;
import com.hgyc.mom.mes.vo.MesStationCollectVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.List;

/**
 * 产品SN过站采集记录Controller
 *
 * @author fwj
 * @since 2025-07-04
 */
@Tag(name = "产品SN过站采集记录控制器", description = "产品SN过站采集记录控制器")
@RestController
@RequestMapping("/mes/station/collect")
public class MesStationCollectController {
    @Autowired
    private MesStationCollectService mesStationCollectService;

    @Operation(summary = "查询产品SN过站采集记录列表", description = "查询产品SN过站采集记录列表")
    @PostMapping("/pageList")
    public Result<IPage<MesStationCollect>> pageList(@Parameter(description = "查询参数") @RequestBody MesStationCollectParam mesStationCollectParam) {
        Page<MesStationCollect> page = new Page<>(mesStationCollectParam.getPage(), mesStationCollectParam.getPageSize());
        MesStationCollect mesStationCollect = new MesStationCollect();
        BeanUtils.copyProperties(mesStationCollectParam, mesStationCollect);
        QueryWrapper<MesStationCollect> wrapper = QueryWrapperUtil.build(mesStationCollect);
        IPage<MesStationCollect> list = mesStationCollectService.page(page, wrapper);
        return Result.success(list);
    }


    @Operation(summary = "获取产品SN过站采集记录详细信息", description = "获取产品SN过站采集记录详细信息")
    @GetMapping(value = "/{id}")
    public Result<?> getInfo(@Parameter(description = "产品SN过站采集记录ID") @PathVariable("id") Long id) {
        return Result.success(mesStationCollectService.getById(id));
    }

    @Operation(summary = "新增产品SN过站采集记录", description = "新增产品SN过站采集记录")
    @PostMapping
    public Result<?> save(@Parameter(description = "产品SN过站采集记录") @RequestBody MesStationCollectVO mesStationCollectVO) {
        mesStationCollectService.saveCollect(mesStationCollectVO);
        return Result.success();
    }

    @Operation(summary = "修改产品SN过站采集记录", description = "修改产品SN过站采集记录")
    @PutMapping
    public Result<?> update(@Parameter(description = "产品SN过站采集记录") @RequestBody MesStationCollectVO mesStationCollectVO) {
        mesStationCollectService.updateCollect(mesStationCollectVO);
        return Result.success();
    }

    @Operation(summary = "删除产品SN过站采集记录", description = "删除产品SN过站采集记录")
    @DeleteMapping
    public Result<?> remove(@Parameter(description = "删除ID") @RequestParam("ids") Long[] ids) {
        return Result.success(mesStationCollectService.removeByIds(Arrays.asList(ids)));
    }

    @Operation(summary = "过站采集条码扫码", description = "过站采集条码扫码")
    @PostMapping("/scan")
    public Result<CollectScanVO> scan(@RequestBody CollectScanVO collectScanVO)
    {
        collectScanVO = mesStationCollectService.scan(collectScanVO);
        return Result.success(collectScanVO);
    }
}